package org.zfes.snowier.cloud.zbss.metting;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zfes.snowier.auth.shiro.suser.AbsSessionUserManager;
import org.zfes.snowier.auth.shiro.suser.SessionUser;
import org.zfes.snowier.cloud.zbss.metting.biz.model.TenantMember;
import org.zfes.snowier.cloud.zbss.metting.biz.service.ITenantMemberService;

@Service("sessionUserManager")
public class CustomUserManagerImpl extends AbsSessionUserManager{
	   @Autowired
	   ITenantMemberService tenantMemberService;
	@Override
	public Optional<SessionUser> loadSessionUserByAccount(String userName) {
		
		Optional<SessionUser> suOp = super.loadSessionUserByAccount(userName);
		
		Optional<TenantMember> memberOp =tenantMemberService.loadByAccount(userName);
		if(memberOp.isPresent()) {
			suOp.get().setTenantId(memberOp.get().getTenantId());
		}
		
		return suOp;
	}

	

}
